<template>
    <el-config-provider :locale="locale">
        <router-view :key="route.fullPath"></router-view>
    </el-config-provider>
</template>

<script setup>
import { useRoute, useRouter } from "vue-router";
import { onErrorCaptured, provide, ref, onMounted } from "vue";
import locale from "element-plus/es/locale/lang/zh-cn";
import * as Icons from "@/utils/icons.js";
import messageTools from "@/utils/message.js";

const route = useRoute();
const router = useRouter();
const hasError = ref(false);

// 提供图标工具给所有子组件
provide("icons", Icons);
provide("message", messageTools);

// 全局错误处理
onErrorCaptured((err, instance, info) => {
    console.error("应用错误:", err);
    console.log("错误来源:", instance);
    console.log("错误信息:", info);

    hasError.value = true;

    // 对于Element Plus相关错误的特殊处理
    if (err.toString().includes("element-plus") || err.toString().includes("icons-vue")) {
        console.warn("检测到Element Plus相关错误，请查看修复方案文档");
    }

    return false; // 防止错误传播
});

onMounted(() => {
    console.log("应用已挂载，欢迎使用就业职通车系统");
});
</script>
